package uk.co.q3c.deplan.server.domain.util.shard;

import javax.persistence.Id;

import uk.co.q3c.deplan.client.admin.AdminObject;

import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.Unindexed;

/**
 * @see DatastoreCounter
 * @author David Sowerby 2 Mar 2010
 * 
 */
@Unindexed
@Cached(expirationSeconds = 600)
public class DatastoreCounterShard implements AdminObject {
	@Id
	private Long key;
	@Indexed
	private String counterName;
	@Indexed
	private int shardNumber;
	private int count;

	public DatastoreCounterShard() {
		super();
	}

	public String getCounterName() {
		return counterName;
	}

	public DatastoreCounterShard(String counterName, int shardNumber, int count) {
		this.counterName = counterName;
		this.shardNumber = new Integer(shardNumber);
		this.count = new Integer(count);
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getShardNumber() {
		return shardNumber;
	}

	public void increment(int amount) {
		count += amount;
	}

	public void setCounterName(String counterName) {
		this.counterName = counterName;
	}

	public void setShardNumber(int shardNumber) {
		this.shardNumber = shardNumber;
	}

	@Override
	public String toString() {
		return "Shard number " + shardNumber + " for counter for '" + counterName + "'.";
	}

	public Long getKey() {
		return key;
	}
}
